﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using InfraWEB.BLL;
using InfraWEB.Comum.Enum;

namespace InfraWEB.UI
{
    public partial class SalaNovo : Base
    {
        protected void Page_Load(object sender, EventArgs e)
        {
			CheckIfUsuarioIsLogged();
			CheckIfUsuarioHasAccessPermission(int.Parse(Enumeration.TipoUsuarioName.AdministradorIndex));
			if (!Page.IsPostBack)
            {
                CarregarTipos();
                CarregarPredios();
            }
        }

        private void CarregarTipos()
        {
            ddlType.Items.Add(new ListItem(
                Enumeration.TipoSalaName.Corredor,
                Enumeration.TipoSalaName.CorredorIndex) { Selected = true });
            ddlType.Items.Add(new ListItem(
                Enumeration.TipoSalaName.SalaAula,
                Enumeration.TipoSalaName.SalaAulaIndex));
            ddlType.Items.Add(new ListItem(
                Enumeration.TipoSalaName.SalaMicros,
                Enumeration.TipoSalaName.SalaMicrosIndex));
            ddlType.Items.Add(new ListItem(
                Enumeration.TipoSalaName.WC,
                Enumeration.TipoSalaName.WCIndex));
        }

        private void CarregarPredios()
        {
            Predio building = new Predio();
            InfraWEB.DAL.Infra.PredioDataTable tabela = building.GetAllPredios();

            foreach (InfraWEB.DAL.Infra.PredioRow item in tabela)
            {
                ddlBuilding.Items.Add(new ListItem(item.PreNome, item.PreId.ToString()));
            }
        }

        protected void btnCadastrar_Click(object sender, EventArgs e)
        {
            Sala room = new Sala();
            string name = txtName.Text;
            int type = ddlType.SelectedIndex;
            int building = int.Parse(ddlBuilding.Text);

            room.RecordSala(name, type, building);
            lblMensagem.Visible = false;
            lblMensagem.Text = "";
            Context.Session["RoomRegisterStatus"] = "true";
            Response.Redirect("~/SalaLista.aspx");
        }

        protected void btnCancelar_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/SalaLista.aspx");
        }
    }
}
